// index.js
// 获取应用实例
const request = require('../../utils/promise')
const url = require('../../utils/link')
var app = getApp()
Page({
  data: {
    // 保存用户名和密码
    passWord:'',
    userName:'',
    // 保存登陆后的返回信息
    q:{},
    left:0,
    leftb:0
  },
  userNameinput:function(e){
    this.setData({
      userName:e.detail.value
    })
  },
  passwordinput:function(e){
    this.setData({
      passWord:e.detail.value
    })
  },

   getinfo:async function(){
        var that = this
        console.log(that.data.userName)
        const { data: res } = await request.post(url.userLogin , {account: that.data.userName , password: that.data.passWord})
        console.log(res)

        //res就是接收后台返回的数据
        that.setData({
          q:res.data
        })
        // 保存token
        wx.setStorage({
         key: "token",
         data: res.data.token
        });
        console.log(res.data.token)
        if(res.code == 20000) {
          wx.switchTab({  url: '/pages/sign/sign' })
        } else {
          wx.showModal({
                title:'注意',
                content:'登录失败'
           })
         }
    },
  onLoad() {
    this.setData({
      left:(wx.getSystemInfoSync().windowWidth)*0.9-150,
      leftb:(wx.getSystemInfoSync().windowWidth)*0.9-130
    })
  },
})

